from celery_tasks.celery import app

import time
import random

from meiduo_mall.libs.yuntongxun.sms import CCP


@app.task(bind=True)
def send_message(self, mobile, sms_code):
    # 增加耗时
    time.sleep(10)
    # 发送短信

    ccp = CCP()
    try:
        result = ccp.send_template_sms(mobile, [sms_code, 5], 1)
    except Exception as e:
        result = -1

    if result == -1:
        self.retry(exc=Exception('发送短信失败'),countdown=5,max_retries=3)
